package cn.edu.sjtu.se.dslab.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.sjtu.se.dslab.dao.IPGroupDao;
import cn.edu.sjtu.se.dslab.project.PGroup;
import cn.edu.sjtu.se.dslab.service.IPGroupService;

@Service("pgroupService")
@Transactional
public class PGroupServiceImpl implements IPGroupService {

	@Resource(name="pgroupDao")
	IPGroupDao pgroupDao;
	
	@Override
	public boolean addPGroup(PGroup pgroup) {
		pgroupDao.save(pgroup);
		return true;
	}

	@Override
	public PGroup updatePGroup(PGroup pgroup) {
		return pgroupDao.update(pgroup);
	}

	@Override
	public PGroup getPGroupById(long id) {
		return pgroupDao.queryById(id);
	}

	@Override
	public List<PGroup> getPGroupList() {
		//return pgroupDao.queryByList();
		return pgroupDao.queryValidPGroups();
	}

	@Override
	public boolean deletePGroup(long id) {
		PGroup pgroup = pgroupDao.queryById(id);
		if (pgroup.isDeleted()) return false;
		pgroup.setDeleted(true);
		pgroupDao.update(pgroup);
		return true;
	}
	
	

}
